import { storeToRefs } from 'pinia';
import { useUserStore } from '@/store/user.js';

export default function useCommonHook(){
	const { token } =storeToRefs(useUserStore()); 
	/* 小程序跳转 */
	const jumpTominiProgram=async(type,productType)=>{
		console.log(token.value,type,productType,'00');

		if(type == 'zfb'){
			// 支付宝小程序
			//  let params = {id: 1, name: '张三'};
			//   let queryEncode = encodeURIComponent(params);
			/* 
			 省心智生活我的页面			appId：2021004157689007    
			路径：pages/my/my			https://ds.alipay.com/?scheme=alipay:alipays://platformapi/startapp?appId=2021004157689007&page=pages/my/my
			 */
			  let schemeEncode = encodeURIComponent('alipays://platformapi/startapp?appId=2021004157689007&page=pages/login/login');
			  let zfbUrl = `https://ds.alipay.com/?scheme=${schemeEncode}`;
			  window.location.href = zfbUrl;
		}else if(type == 'wx'){
			// 微信小程序
			location.href = 'weixin://dl/business/?appid=wxd288833c4af82e86&path=pages/index/index';
		}else if(type == 'h5'){
			// 有没得 token 没得要去登录页面登录
			if(!token.value){
				uni.navigateTo({ url: `/pages/h5-login/h5-login?productType=${productType?productType:''}` });
			}else{
				uni.navigateTo({ url: '/pages/lhhy/orderList' });
			}
			
		}
	};
	/* 电话 */
	const phone=()=>{
		uni.makePhoneCall({ phoneNumber: '400-8825101' //客服
		});
	};
	return{ jumpTominiProgram,phone };
}